//
//  MZExtensionUIScrollview.swift
//  MZTool
//
//  Created by gby on 2023/3/1.
//

import Foundation

extension UIScrollView: UIGestureRecognizerDelegate{
    
    private struct UIScrollViewPropertyKeys{
        static var scrollViewPopGestureRecognizerEnable_key = "mz_scrollViewPopGestureRecognizerEnable_key"
    }
    
    public var mz_scrollViewPopGestureRecognizerEnable: Bool{
        get {
            guard let bools = objc_getAssociatedObject(self, &UIScrollViewPropertyKeys.scrollViewPopGestureRecognizerEnable_key) as? Bool else {
                return false
            }
            return bools
        }
        set { objc_setAssociatedObject(self, &UIScrollViewPropertyKeys.scrollViewPopGestureRecognizerEnable_key, newValue, .OBJC_ASSOCIATION_ASSIGN) }
    }
    
    open func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        if self.mz_scrollViewPopGestureRecognizerEnable, self.contentOffset.x <= 0, let gestureDelegate = otherGestureRecognizer.delegate {
            if let mzfclass = NSClassFromString("_MZFullscreenPopGestureRecognizerDelegate") {
                if gestureDelegate.isKind(of: mzfclass.self) {
                    return true
                }
            }
        }
        return false
    }
}
